package hbec.kettle.etl;

import java.util.Map;

import org.apache.log4j.Logger;

import hbec.kettle.etl.common.constants.ExitStatus;
import hbec.kettle.etl.common.exception.ExceptionTracker;
import hbec.kettle.etl.engine.conf.EngineConf;
import hbec.kettle.etl.engine.conf.JobConf;
import hbec.kettle.etl.engine.conf.ParseXMLUtil;
import hbec.kettle.etl.engine.conf.PluginConf;
import hbec.kettle.etl.engine.schedule.Engine;
import hbec.kettle.etl.engine.tools.JobConfGenDriver;

public class BootStrap {
	private static final Logger logger = Logger.getLogger(BootStrap.class);
	
	public static void main(String[] args) {
		String jobDescXml = JobConfGenDriver.produceXmlConf();
		JobConf jobConf = ParseXMLUtil.loadJobConfig(jobDescXml);
		EngineConf engineConf = ParseXMLUtil.loadEngineConfig();
		Map<String, PluginConf> pluginConfs = ParseXMLUtil.loadPluginConfig();
		logger.info("Engine config initialize finished.");
		
		Engine engine = new Engine(engineConf, pluginConfs);
		try {
			engine.start(jobConf);
		} catch (Exception e) {
			logger.error(ExceptionTracker.trace(e));
			System.exit(ExitStatus.FAILED.value());
		}
		System.exit(0);
	}
}
